﻿<cfscript>
/** 
* ORM Campus
* 
* @hint "Hibernate persistenter t_campus. 定义了学校的有关校区的数据项" 
* 
*/ 

component 
	displayname="public.service.orm.senate.Campus" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="Campus" 
	table="t_campus"
	{

	property type="string" name="CampusID" column="campus_id" fieldtype="id" generator="assigned" hint="校区代码";
	
	property type="string" name="CampusName" column="campus_name" hint="校区名称";
	property type="string" name="Address" column="campus_address" hint="校区地址";
	property type="string" name="ZipCode" column="campus_zipcode" hint="校区邮编";

	property name="Buildings" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="campus_id" cfc="Building" hint="园区中建筑物";
	property name="Classrooms" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="campus_id" cfc="Classroom" hint="园区中教室";
	property name="FormClasses" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="campus_id" cfc="FormClass" hint="园区中行政班";

	property name="ProgramTasks" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="campus_id" cfc="ProgramTask" hint="园区中上课的计划任务";
	property name="CommonTasks" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="campus_id" cfc="CommonTask" hint="园区中上课的全校通选课任务";
	property name="OpenTasks" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="campus_id" cfc="OpenTask" hint="园区中上课的单开班教学任务";

	property name="Exams" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="campus_id" cfc="ExamTask" hint="园区中教学任务考试安排情况";
	property name="ResitExams" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="campus_id" cfc="ExamResitTask" hint="园区中补考任务考试安排情况";
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getNextID() output=false {
		
		var nextID = numberFormat(1, "0_");
		var checkArray = ORMExecuteQuery("select CampusID from Campus 
											order by CampusID desc", {}, { maxResults=1 });
		
		/* 
			主键生成规则 CHAR(2)
			
			2位为流水号 校区自动编码
			
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = numberFormat((checkArray[1] + 1), "0_");
			
		}

		return nextID;
	}
	
}

</cfscript>